<?php $this->load->view('templates/backend/header'); ?>
<h3><?php echo $this->lang->line("update_list_fly");?></h3>
<style>
    .fone_num_cls{
        width:15%;  vertical-align: top;
    }
    .navbar-inverse{
        display: none;
    }
    body{
        padding-top:10px;
        padding-bottom:30px;
    }
</style>
<?php if (isset($flash_message)  && $flash_message!=NULL ): ?>
<div class="alert alert-success"><a class="close" flyTomorrow-dismiss="alert">x</a><strong><?php echo $flash_message; ?></strong></div>
<?php endif; ?>
<div class="well">
    <?php echo form_open();?>
        <div class="tab-content">	
            <div class="tab-pane active" id="main">
                <?php
                echo form_input(array('type'=>'hidden', 'name' => 'customerID', 'id' => 'customerID', 'value' =>$flyTomorrow->customerID));
                echo form_input(array('type'=>'hidden', 'name' => 'id', 'id' => 'id', 'value' =>$flyTomorrow->id));
                echo form_label($this->lang->line('name'), 'name');
                echo form_input(array('readonly' => 'true', 'name' => 'name', 'id' => 'name', 'value' => $flyTomorrow->name));
                echo form_error('name');
                
                //phone
                echo form_label($this->lang->line('phone'), 'phone');
                foreach($flyTomorrow->phone as $values){
                    echo form_input(array('readonly' => 'true', 'name' => 'phone', 'id' => 'phone', 'value' =>$values,'class'=>'fone_num_cls'));
                }
                echo form_error('phone');
                echo ' ';
                echo form_button(array('id'=>'phone_callback','value' => '3', 'name' => 'callback', 'content' => $this->lang->line('phone_callback'),'class' => 'btn btn-success')).' ';
                echo form_button(array('id'=>'phone_callok','value' => '4', 'name' => 'callok', 'content' => $this->lang->line('phone_callok'),'class' => 'btn btn-success')).' ';
                echo form_input(array('type'=>'hidden', 'name' => 'phone_callstatus', 'id' => 'phone_callstatus', 'value' =>''));
                
                //mã ??t ch?
                echo form_label($this->lang->line('booking_place_code'), 'booking_place_code');
                echo form_input(array('readonly' => 'true','name' => 'booking_place_code', 'id' => 'booking_place_code', 'value' => $flyTomorrow->booking_place_code));
                echo form_error('booking_place_code');
                
                //hãng
                echo form_label($this->lang->line('airline'), 'airline');
                echo form_input(array('readonly' => 'true','name' => 'airline', 'id' => 'airline', 'value' => $flyTomorrow->airline));
                echo form_error('airline');
                
                //ngày bay ??u
                echo form_label($this->lang->line('ngay_dau_bay'), 'ngay_dau_bay');
                echo form_input(array('readonly' => 'true','name' => 'ngay_dau_bay', 'id' => 'ngay_dau_bay', 'value' => date("d-m-Y",strtotime($flyTomorrow->ngay_dau_bay))));
                echo form_error('ngay_dau_bay');
				
		//hanh trinh
                
				echo form_label($this->lang->line('ship'), 'ship');
                echo form_textarea(array('readonly' => 'true','name' => 'ship', 'id' => 'ship', 'value' => $flyTomorrow->ship,'rows'=>'3'));
                echo form_error('ngay_dau_bay');
				
				echo form_label($this->lang->line('newship'), 'newship');
                echo form_textarea(array('readonly' => 'true','name' => 'newship', 'id' => 'newship', 'value' => $flyTomorrow->loadship,'rows'=>'5'));
                echo form_error('newship');
				
		//dk ve
                echo form_label($this->lang->line('dkve'), 'dkve');
                echo form_textarea(array('readonly' => 'true','name' => 'ship', 'id' => 'ship', 'value' => $flyTomorrow->dkve,'rows'=>'5'));
                echo form_error('ngay_dau_bay');
				
		//dk hanh li
                echo form_label($this->lang->line('dkhanhly'), 'dkhanhly');
                echo form_textarea(array('readonly' => 'true','name' => 'ship', 'id' => 'ship', 'value' => $flyTomorrow->dkhanhly,'rows'=>'5'));
                echo form_error('ngay_dau_bay');
                
                //Ghi chú khách hàng
                echo form_label($this->lang->line('note'), 'note');
                echo form_textarea(array('name' => 'note', 'id' => 'note', 'value' => $flyTomorrow->note,'rows'=>'5'));
                echo form_error('note');
                ?>
            </div>
        </div>
        <div class="top-button">
                <?php echo form_button(array('id' => 'submit', 'value' => 'Update', 'name' => 'submit', 'type' => 'submit', 'content' => $this->lang->line('save'),'class' => 'btn btn-primary')); ?>
                <?php echo form_button(array('id' => 'cancel','content' => $this->lang->line('close'),'class' => 'btn btn-danger')); ?>
        </div>
    <?php form_close();?>
    <span id="simple-msg-submit"></span>
</div>

<?php $this->load->view('templates/backend/footer'); ?>
<script>
$(document).ready(function() {
    $('button[type="submit"]').attr('disabled','disabled');
    $( "#phone_callback" ).on('click',function() {
        document.getElementById("phone_callstatus").value           = $(this).val();
        document.getElementById("phone_callback").className         = "btn btn-danger";
        document.getElementById("phone_callok").className           = "btn btn-success";
        $('button[type="submit"]').removeAttr('disabled');
        $('#phone_callok').attr('disabled','disabled');
        
    });
    
    $( "#phone_callok" ).on('click',function() {
        document.getElementById("phone_callstatus").value           = $(this).val();
        document.getElementById("phone_callback").className         = "btn btn-success";
        document.getElementById("phone_callok").className           = "btn btn-danger";
        $('button[type="submit"]').removeAttr('disabled');
        $('#phone_callback').attr('disabled','disabled');
    });

    $("#submit").on('click',function(e){
            setTimeout(function () {
                $.ajax(
                    {
                        url : '/auth/flyTomorrow/updateInfo/',
                        type: "POST",
                        data : { airline:$("#airline").val(),booking_place_code:$("#booking_place_code").val(),customerID:$("#customerID").val(),phone: $("#phone").val(),id: $("#id").val(), phone_callstatus: $("#phone_callstatus").val(), note: $("#note").val()},
                        cache: false,
                        beforeSend: function(){
                            
                        },
                        success:function(data) 
                        {
                            if(data == 1){
                                window.top.location.href="/auth/flyTomorrow/";
                            }
                        },
                        error: function() 
                        {
                            alert("L?i! Contact Admin!");
                        }
                    });
            }, 222);
            e.preventDefault();	//STOP default action
    });
    
    $("#cancel").on('click',function(e){
            setTimeout(function () {
                $.ajax(
                    {
                        url : '/auth/flyTomorrow/updateStatus/',
                        type: "POST",
                        data : { id: $("#id").val(), status: 0},
                        cache: true,
                        beforeSend: function(){
                            
                        },
                        success:function(data) 
                        {
                            parent.jQuery.fancybox.close();
                        },
                        error: function() 
                        {
                            alert("Lỗi! Contact Admin!");
                        }
                    });
            }, 111);
            e.preventDefault();	//STOP default action
    });
    wireUpEvents();
});

function wireUpEvents(){
    function goodbye(e){
        $.ajax(
            {
                url : '/auth/flyTomorrow/updateStatus/',
                type: "POST",
                data : { id: $("#id").val(), status: 0},
                cache: true,
            });
        //return false;
    }
    window.onbeforeunload=goodbye;
}
</script>